
public class Maze {
	private MazeNodes nodes;
	private MazeEdges edges;
	private int startFQ;

	
	
	public MazeNodes getNodes() {
		return nodes;
	}

	public MazeEdges getEdges() {
		return edges;
	}
	
	public int getStartFQ() {
		return startFQ;
	}
	
	public void setStartFQ(int fq) {
		startFQ = fq;
	}

	public Maze() {
		this.edges = null;
		this.nodes = null;
	}

	public void insertMazeNode(MazeNode node) {
		if (nodes != null) {
			int len = nodes.size();
			for (int i = 0; i < len; i++) {
				MazeNode current = nodes.get(i);
				if (current.equals(node))
					return;
			}
		} else {
			nodes = new MazeNodes();
		}
		nodes.add(node);
	}

	public void insertMazeEdge(MazeEdge edge) {
		if(edges != null){
			int len = edges.size();
			for(int i = 0; i < len; i++){
				MazeEdge current = edges.get(i);
				if(current.equals(edge))
					return;
			}
		} else {
			edges = new MazeEdges();
		}
		edges.add(edge);
	}

	public MazeEdges getAdjacencyEdges(MazeNode source_node) {
		MazeEdges adjacency_edges = new MazeEdges();
		int len = edges.size();
		for (int i = 0; i < len; i++) {
			if (edges.get(i).getSource().equals(source_node))
				adjacency_edges.add(edges.get(i));
		}
		return adjacency_edges;
	}

	public MazeNode findAndCreate(String NodeName) {
		// TODO Auto-generated method stub
		if (nodes != null) {
			int len = nodes.size();
			for(int i = 0; i < len; i++){
				MazeNode current = nodes.get(i);
				if(current.getName().compareTo(NodeName) == 0){
					return current;
				}
			}
		}
		MazeNode node;
		if (NodeName.startsWith("Troll")) { // this is a troll node
			node = new MazeNode(NodeName, MazeNode.Type.TROLL, 0, Integer.MAX_VALUE);
		
		} else if (NodeName.startsWith("Treasure")) { // this is the treasure node
			node = new MazeNode(NodeName, MazeNode.Type.TREASURE, 0, 0);
		} else { // this is a banal node
			node = new MazeNode(NodeName, MazeNode.Type.BANAL, 0, 0);
		}
		this.insertMazeNode(node);
		return node;
	}
	
	public MazeEdge findMazeEdge(MazeNode source, MazeNode destination){
		if (edges != null){
			int len = edges.size();
			for(int i = 0; i < len; i++){
				MazeEdge current = edges.get(i); 
				if(current.getSource().equals(source) && current.getDestination().equals(destination))
					return current;
			}
		} 
		return null;
		
	}
}
